package cn.siriusbot.siriuspro.bot.event.impl;

import cn.siriusbot.siriuspro.admin.service.ServerConfigService;
import cn.siriusbot.siriuspro.bot.BotApi;
import cn.siriusbot.siriuspro.bot.annotation.OnBotEvent;
import cn.siriusbot.siriuspro.bot.api.pojo.User;
import cn.siriusbot.siriuspro.bot.api.tuple.Tuple;
import cn.siriusbot.siriuspro.bot.client.BotClient;
import cn.siriusbot.siriuspro.bot.event.SpringBootEvent;
import cn.siriusbot.siriuspro.bot.event.v1.EventMethodNoParam;
import cn.siriusbot.siriuspro.bot.pojo.e.BotEventType;
import cn.siriusbot.siriuspro.uitls.AppContextUtil;

public class SpringBootEventImpl implements SpringBootEvent, EventMethodNoParam {

    BotClient client;

    /**
     * 注入客户端对象，并初始化
     *
     * @param client
     */
    @Override
    public void init(BotClient client) {
        this.client = client;
    }

    /**
     * 机器人登录事件
     */
    @Override
    public void start() {

    }

    @OnBotEvent
    @Override
    public void onEvent(BotEventType type) {
        if (type == BotEventType.BOT_LOGIN_END) {
            //  登录结束后事件
            BotApi botApi = AppContextUtil.getBean(BotApi.class);
            ServerConfigService serverConfigService = AppContextUtil.getBean(ServerConfigService.class);
            Tuple<User, String> robotInfo = botApi.userApi().getRobotInfo(client.getInfo().getBotId());
            String avatar = robotInfo.getFirst().getAvatar();
            serverConfigService.addConfig("bot.avatar." + this.client.getInfo().getBotId(), avatar);
//            System.out.println(avatar);
        }
    }
}
